/**
 * Created by dqw on 2015/12/30.
 */

//列表开始
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true

    },
    {
        id: 'u.userName',
        title: '用户名',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'u.mobile',
        title: '手机号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'bankCode',
        title: '银行编码',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false,
    },
    {
        id: 'bankName',
        title: '银行名称',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'bankNo',
        title: '银行卡号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false,
    },
    {
        id: 'realName',
        title: '持卡人姓名',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'mobile',
        title: '预留手机号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'idCard',
        title: '持卡人身份证',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false,
    },
    {
        id: 'createTime',
        title: '绑卡时间',
        type: 'date',
        format:'yyyy-MM-dd',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'range'
    }
    // {
    //     id: 'status',
    //     title: '状态',
    //     type: 'int',
    //     headerClass: 'text-center',
    //     columnClass: 'text-center',
    //     fastSort: false,
    //     fastQuery: true,
    //     fastQueryType: 'eq',
    //     codeTable: {
    //         1: $lang.bankRefuseStatus.T1,
    //         2: $lang.bankRefuseStatus.T2,
    //         3: $lang.bankRefuseStatus.T3
    //     }
    // }
    // {
    //     id: 'operation',
    //     title: '操作',
    //     type: 'string',
    //     columnClass: 'text-center',
    //     fastSort: false,
    //     resolution: function (value, record, column, grid, dataNo, columnNo) {
    //         var view = "<a data-target='#lookModal' class='btn btn-sm btn-primary m-r-10' data-toggle='modal' data-no='" + dataNo + "' ><i class='fa fa-eye Example of eye'></i>&nbsp;查看&nbsp;</a>", pass = "", refuse = "";
    //         var html, audit = "";
    //         if (record.status == 1){
    //             audit += "<a data-target='#editModal' class='btn btn-sm btn-primary m-r-10' data-toggle='modal' data-no='" + dataNo + "' ><i class='fa fa-edit'></i>&nbsp;审核&nbsp;</a>";
    //         }
    //         html = view + audit;
    //         return html;
    //     }
    // },
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + '/userBank/json/list',
    exportURL: ncGlobal.adminRoot + 'userBank/json/export',
    exportFileName: '我的银行列表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    tools: 'refresh|faseQuery|export[excel]',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int:["id","type","status"],Timestamp:["certificateTime"]}
};

var grid = $.fn.DtGrid.init(dtGridOption);
//默认查询条件
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_delFlag'] = 1;
//排序
grid.sortParameter.columnId = ['asc_status'];
//列表结束

//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {

        // 编辑借款标对话框
        $('#editModal').on('show.bs.modal', function (event) {
            var    //获取接受事件的元素
                button = $(event.relatedTarget),
                //获取data 参数
                datano = button.data('no'),
                modal = $(this),
                //获取列表框中的原始数据
                gridData = grid.sortOriginalDatas[datano],
                editForm = $("#editForm");
            //清除错误提示
            editForm.psly().reset();
            $(".alert-danger").remove();
            modal.find('input[name="id"]').val(gridData.id);
            modal.find('input[name="branch"]').val(gridData.branch);
            modal.find('input[name="province"]').val(gridData.province);
            modal.find('input[name="city"]').val(gridData.city);
            modal.find('input[name="remark"]').val(gridData.remark);
            $('#editFormPicImg').attr('src', ncGlobal.fileRoot + gridData.cardPic);
            modal.find('textarea[name="remark"]').val('');
            $(".status").bootstrapSwitch('state', true);
        });

        $("#lookModal").on("show.bs.modal", function (event) {
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            //获取data 参数
            var datano = button.data('no');
            var modal = $(this);
            //获取列表框中的原始数据
            var gridData = grid.sortOriginalDatas[datano];

            modal.find('input[name="branch"]').val(gridData.branch);
            modal.find('input[name="province"]').val(gridData.province);
            modal.find('input[name="city"]').val(gridData.city);
            modal.find('input[name="remark"]').val(gridData.remark);
            $('#lookFormPicImg').attr('src', ncGlobal.fileRoot + gridData.cardPic);
        });

        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['lk_u.user_name_or_lk_u.mobile_or_lk_bank_name_or_lk_bank_no'] = $('#keyword').val();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    //外部可调用
    return {
        bindEvent: _bindEvent
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});